<?php
//首页控制器
class IndexAction extends MessageAction {
    /**
     * [index description]首页跳转
     * @return [type] [description]
     */
    public function index(){
        if(!session('?employe_id') || session('employe_id')<0)
        {
            $this->redirect('__APP__/Login/index');
        }
        //获取顶部数据
        $employe_id=session('employe_id');
        $this->employeData=$this->getNowEmploye($employe_id);
        $employe_department_id=$this->getOneField('employe_department_id',$employe_id);
        $dpt_name=$this->getDepartmentName($employe_department_id);
        $employe_position_id=$this->getOneField('employe_position_id',$employe_id);
        $position_name=$this->getPositionName($employe_position_id);
        $this->assign('dptName',$dpt_name);
        $this->assign('position',$position_name);

        $msgCount=$this->getMsgCount();
        $this->assign('msgCount',$msgCount);
        
        //获取欢迎页数据
        //新闻
        $newsData=array();
        $info=M('Information');
        $data=$info->where("info_type='新闻'")->order('info_time desc')->select();
        foreach ($data as $value) {
            $value['info_employe_id']=$this->getOneEmployeName($value['info_employe_id']);
            $newsData[]=$value;
        }
        $this->newsData=$newsData;
        //公告
        $adData=array();
        $data=$info->where("info_type='公告'")->order('info_time desc')->select();
        foreach ($data as $value) {
            $value['info_employe_id']=$this->getOneEmployeName($value['info_employe_id']);
            $adData[]=$value;
        }
        $this->adData=$adData;


        //待审批
        $process=M('Process');
        $count1=$process->where("process_now_id='".$employe_id."' and process_state=1 and process_now_id_if_approval=0")->count();
        $this->assign('count1',$count1);

        //我的申请
        $count2=$process->where("process_begin_id='".$employe_id."' and process_parent_id=0")->count();
        $this->assign('count2',$count2);

        //草稿箱
        $count3=$process->where("process_begin_id='".$employe_id."' and process_state=0")->count();
        $this->assign('count3',$count3);

        //获取权限列表
        $permissionList=$this->havePermission();
        $this->assign('permissionList',$permissionList);

		$this->display('Index:index');
    }

    /**
     * [employeList description]员工列表
     * @return [type] [description]
     */
    public function employeList(){
    	$employe=M('Employe');
    	$this->data=$employe->select();
    	$this->display('Index:employeList');
    }


    /**
     * [leaveListData description]获取请假列表
     * @return [type] [description]
     */
    public function employeListData(){
    	$result = array();
    	$result['total'] = $this->getListCount();
    	$result['rows'] = $this->getList();
    	echo json_encode($result);
    }

    /**
     * 获取列表
     */
    public function getList()
    {
    	import("ORG.Util.Page");
    	$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    	$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        //$page = intval($_POST["page"]);
        //$rows = intval($_POST['rows']);
       	$employe=M('Employe');
       	$result=$employe->page($page,$rows)->select();
        return $result;
    }
    
    /**
     * 获取列表数量
     */
    public function getListCount()
    {	
    	$employe=M('Employe');
    	$result=$employe>count();
        return $result;
    }

}